/**
 * Slot Machine, July 2012
 *
 * Owner: Rami Abou Ghanem
 * Owner: Sumbul Alvi
 *
 */

package Backend;

public class SlotsInfo {
	private int numberOfSlots;
    private SlotNumber slots[][];
    
    public SlotsInfo(int numOfSlots)
    {
    	numberOfSlots = numOfSlots;
    	slots = new SlotNumber[numOfSlots][numOfSlots];
    	for(int i = 0; i < numberOfSlots; i++)
    	{
    		for(int j = 0; j < numberOfSlots; j++)
    		{
    			slots[i][j] = new SlotNumber();
    		}
    	}
    }
    
    public void generateSlots()
    {
    	for(int i = 0; i < numberOfSlots; i++)
    	{
    		for(int j = 0; j < numberOfSlots; j++)
    		{
    			slots[i][j].generateValue();
    		}
    	}
    }
    
    public int checkSlotsForWin(int numLines)
    {
    	int winnings = 0;
    	
    	if(1 == numLines)
    	{
    		int i = 0;
    		for(i = 1; i < numberOfSlots; i++)
    		{
    			if(slots[1][0].getValue() != slots[1][i].getValue())
    			{
    				break;
    			}
    		}
    		
    		if(i == numberOfSlots)
    		{
    			winnings = slots[1][0].getValue();
    		}
    	}
    	else if(numLines > 1 && numLines < numberOfSlots)
    	{
    		//Not sure how to deal with this case
    	}
    	else if(numLines >= numberOfSlots)
    	{
    		int j, i;
    		for(j = 0; j < numberOfSlots; j++)
    		{
    			for(i = 1; i < numberOfSlots; i++)
    			{
    				if(slots[j][0].getValue() != slots[j][i].getValue())
        			{
        				break;
        			}
    			}
    			
    			if(i == numberOfSlots)
        		{
        			winnings += slots[j][0].getValue();
        		}
    		}
    	}
    	
    	//Deal with diagonals
    	if(numLines == numberOfSlots + 2)
    	{
    		//Top right corner diagonal
    		int i = 0;
    		for(i = 1; i < numberOfSlots; i++)
    		{
    			if(slots[0][0].getValue() != slots[i][i].getValue())
    			{
    				break;
    			}
    		}
    		
    		if(i == numberOfSlots)
    		{
    			winnings += slots[0][0].getValue();
    		}
    		
    		//Bottom right corner diagonal
    		for(i = numberOfSlots - 2; i >= 0; i--)
    		{
    			if(slots[numberOfSlots-1][0].getValue() != slots[i][numberOfSlots-1-i].getValue())
    			{
    				break;
    			}
    		}
    		
    		if(i == -1)
    		{
    			winnings += slots[numberOfSlots-1][0].getValue();
    		}
    	}
    	
    	return winnings;
    }
    
    public void display()
    {
    	System.out.println("Slot machine results:");
    	for(int i = 0; i < numberOfSlots; i++)
    	{
    		for(int j = 0; j < numberOfSlots; j++)
    		{
    			System.out.print(slots[i][j].getValue() + "  ");
    		}
    		System.out.println();
    	}
    }
    
/*	public static void main(String[] args)
	{
		int numSlots = 3;
		SlotsInfo slots = new SlotsInfo(numSlots);
		UserCoins coins = new UserCoins();
		
		slots.generateSlots();
		slots.display();
	}*/
}
